﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data.SqlClient;
using System.Data;
using System.Configuration;

public partial class myOrder : System.Web.UI.Page
{
    string strconn = ConfigurationManager.ConnectionStrings["a123"].ToString();
    SqlConnection sqlconn;
    string text;
    protected void Page_Load(object sender, EventArgs e)
    {
        text = Request.QueryString["id"];
        if (!IsPostBack)
        {
            if (text == null)
            {
                bind();
            }
            else { 
                binc();
                Response.Write("<script>alert('删除成功！')</script>");
            }
            bind();
        }
    }
    public void binc()
    {
        sqlconn = new SqlConnection(strconn);
        for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
        {
            System.Web.UI.WebControls.CheckBox checkbox = (System.Web.UI.WebControls.CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
            string sqlstr = "delete from tb_OrderInfo where userName='" + Session["ID"] + "' and OrderID='" + text + "'";
            sqlconn.Open();
            SqlCommand sqlcom = new SqlCommand(sqlstr, sqlconn);
            sqlcom.ExecuteNonQuery();
            sqlconn.Close();
        }
    }
    public void bind()
    {
        sqlconn = new SqlConnection(strconn);
        sqlconn.Open();
        string sqlstr = "select * from tb_OrderInfo where UserName='"+Session["ID"]+"'";
        SqlDataAdapter myda = new SqlDataAdapter(sqlstr, sqlconn);
        DataSet myds = new DataSet();
        myda.Fill(myds, "tb_OrderInfo");
        GridView1.DataSource = myds;
        GridView1.DataKeyNames = new string[] { "OrderID" };
        GridView1.DataBind();
        sqlconn.Close();

        //sqlconn = new SqlConnection(strconn);
        for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
        {
            string IsSend;
            string IsConfirm;
            System.Web.UI.WebControls.CheckBox checkbox1 = (System.Web.UI.WebControls.CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
            System.Web.UI.WebControls.CheckBox checkbox2 = (System.Web.UI.WebControls.CheckBox)GridView1.Rows[i].FindControl("CheckBox2");
            System.Web.UI.WebControls.HyperLink hyperlink1 = (System.Web.UI.WebControls.HyperLink)GridView1.Rows[i].FindControl("HyperLink1");
            System.Web.UI.WebControls.HyperLink hyperlink2 = (System.Web.UI.WebControls.HyperLink)GridView1.Rows[i].FindControl("HyperLink2");
            System.Web.UI.WebControls.HyperLink hyperlink5 = (System.Web.UI.WebControls.HyperLink)GridView1.Rows[i].FindControl("HyperLink5");
            //string number = GridView1.Rows[0].Cells[1].Text;
            if (checkbox1.Checked)
            {
                IsSend = "已发货";

            }
            else { IsSend = "未发货"; }
            if (checkbox2.Checked)
            { IsConfirm = "已付款"; }
            else
            {
                IsConfirm = "去付款";
                hyperlink2.NavigateUrl = "~/checkOut.aspx?id=" + GridView1.DataKeys[i].Value;
                hyperlink5.NavigateUrl = "~/myOrder.aspx?id=" + GridView1.DataKeys[i].Value;
                hyperlink5.Text = "删除该订单";
            }
            //Label1.Text = IsSend;
            hyperlink1.Text = IsSend;
            hyperlink2.Text = IsConfirm;
        }
    }
}